'''
Created on Apr 15, 2012
TestCase ID: Ecom_5012
Description : Kiem thu chuc nang sua thong tin mot loai bai hoc
@author: Vu Dao
'''
import unittest
import time
import HTMLTestRunner
from Functions.globalFunc import preCondition, readData, endCondition
from Functions.loginPageFunc import login
from Functions.administratorFunc import clickOnBtnCategories
from Functions.categoryFunc import clickOnCategoryName, createNewCategory,\
    isCategoryCreatedSuccessfully

username = readData("username")
password = readData("password")
categoryNameAfter = readData("categoriesLesson", index = 3)
categoryNameBefor = readData("categoriesLesson", index = 2)
class Ecom_5012(unittest.TestCase):


    def setUp(self):
        print "Buoc 1: Dang nhap vao website"
        preCondition(self)

    def test_Ecom_5012(self):
        print "Buoc 2: Dang nhap vao website"
        login(self,username, password)
        
        print "Buoc 3: Click vao category"
        clickOnBtnCategories(self)
        
        print "Buoc 4: Click vao loai bai hoc muon thay doi thong tin"
        clickOnCategoryName(self,categoryNameBefor)
        
        print "Buoc 5: Sua thong tin cua bai hoc"
        createNewCategory(self,categoryNameAfter)
        
        print "Buoc 6: Kiem tra Loai bai hoc da duoc sua thong tin thanh cong hay chua"
        self.assertTrue(isCategoryCreatedSuccessfully(self,categoryNameAfter), "Failed: Bai hoc chua duoc sua thong tin thanh cong")
        print "Passed: Bai hoc da duoc sua thong tin thanh cong"
        
    def tearDown(self):
        print "Buoc 7: Dong website"
        endCondition(self)


if __name__ == "__main__":
    #import sys;sys.argv = ['', 'Test.testName']
    testSuite = unittest.TestSuite()
    suite = unittest.TestLoader().loadTestsFromTestCase(Ecom_5012)
    dateTime = time.strftime('%Y%m%d_%H_%M_%S')
    buf = file("../../Report/TestResults" + "_" + dateTime + ".html",'wb')
    runner = HTMLTestRunner.HTMLTestRunner(
                    stream=buf,
                    title='Test Results',
                    description='Kiem thu chuc nang sua thong tin mot loai bai hoc'
                    )
    runner.run(suite)